package org.example.com.Demo;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class ListRedisDemo {
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    public void a(){
        ListOperations<String, String> ops = stringRedisTemplate.opsForList();
        ops.leftPush("A","aa");
        ops.leftPush("A","bb");
        ops.leftPush("A","cc");
        ops.leftPush("A","dd");
        ops.leftPushAll("A","ee","ff","gg");
        ops.rightPush("A","11");
        ops.rightPush("A","22");
        ops.rightPush("A","33");
        ops.rightPush("A","44");
        ops.rightPushAll("A","55","66","77");
    }
    public void b(){
        ListOperations<String, String> ops = stringRedisTemplate.opsForList();
        String a5=ops.index("A",5);
        String a11=ops.index("A",11);
        log.info("a5:{},a11{}", a5, a11);
        List<String> alllist=ops.range("A",0,-1);
        List<String> list1=ops.range("A",1,6);
        log.info("alllist:{}",alllist);
        log.info("list1:{}",list1);


    }
    public void c(){
        ListOperations<String, String> ops = stringRedisTemplate.opsForList();
        Long size=ops.size("A");
        ops.set("A",2,"kk");
        ops.remove("A",4,"aa");
    }
}
